#!/bin/sh

set -e

case "$1" in
    configure)
        # Create user to run the service as
        if [ -z "`id -u scrapy 2> /dev/null`" ]; then
          adduser --system --home /var/lib/scrapyd --gecos "scrapy" \
                  --no-create-home --disabled-password \
                  --quiet scrapy || true
        fi

        chown scrapy:nogroup /var/log/scrapyd \
            /var/lib/scrapyd /var/lib/scrapyd/eggs /var/lib/scrapyd/dbs

        update-python-modules -p # so upstart restart uses the new code
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

#DEBHELPER#

exit 0


